﻿function ClientAddAlbum()
{
    belongSite=document.getElementById("drpSelectSiteForAlbum").options[document.getElementById("drpSelectSiteForAlbum").selectedIndex].value;
    Url=Portal.CMS.Album.GetAddGroupNewUrl(belongSite).value;
    window.open(Url, '_blank');
//    FilterFunc();
}

function ClientSaveAddAlbum()
{
    belongSite=document.getElementById("txtBelongSite").value;
    Subject=document.getElementById("txtAlbum").value;
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    AlbumTypeIndex = document.getElementById("drpSelectAlbumType").selectedIndex;
    AlbumType = document.getElementById("drpSelectAlbumType").options[AlbumTypeIndex].value;
    RetValue = Portal.CMS.AddAlbum.ServerSideAddAlbum(belongSite, language, Subject, AlbumType).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}

function ClientDeleteAlbum(AlbumId)
{
    Msg=Portal.CMS.Album.GetConfirmDeleteMsg().value;
    if(confirm(Msg)==false)return;
    RetValue = Portal.CMS.Album.ServerSideDeleteAlbum(AlbumId).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    FilterFunc();
}

function ShowClientUpdateUrlForm(AlbumId)
{
    Url=Portal.CMS.Album.GetShowUpdateForm(AlbumId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
    //FilterFunc();
}

function ClientSaveUpdateAlbum(AlbumId)
{
    Subject = document.getElementById("txtAlbum").value;
    AlbumTypeIndex = document.getElementById("drpSelectAlbumType").selectedIndex;
    AlbumType = document.getElementById("drpSelectAlbumType").options[AlbumTypeIndex].value;
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    RetValue = Portal.CMS.UpdateAlbum.ServerSideUpdateAlbum(language, AlbumId, Subject, AlbumType).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}


function ShowClientAlbumItemUrlForm(AlbumId)
{
    Url=Portal.CMS.Album.GetShowAlbumItemsForm(AlbumId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_blank');
}


function ClientShowAddAlbumItemRootForm(AlbumId)
{
    Url=Portal.CMS.AlbumItems.GetAddAlbumItemFormUrl(AlbumId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_blank');
    //language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    //document.getElementById("divContentData").innerHTML=Portal.CMS.AlbumItems.GetHtml(language,AlbumId).value;
}

function ClientShowAddAlbumItemSubForm(AlbumId,ParentAlbumItemId)
{
    Url=Portal.CMS.AlbumItems.GetAddSubAlbumItemFormUrl(AlbumId,ParentAlbumItemId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    //language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    //document.getElementById("divContentData").innerHTML=Portal.CMS.AlbumItems.GetHtml(language,AlbumId).value;
}



function ClientShowUpdateAlbumItemSubForm(AlbumId,AlbumItemId)
{
    Url=Portal.CMS.AlbumItems.GetUpdateSubAlbumItemFormUrl(AlbumId,AlbumItemId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    //language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    //document.getElementById("divContentData").innerHTML=Portal.CMS.AlbumItems.GetHtml(language,AlbumId).value;
}

function ClientSaveAddAlbumItem(AlbumId)
{
    MaxItems=document.getElementById("txtMaxItems").value;
    SaveItems=Portal.CMS.AddAlbumItem.CreateSaveItemsObject(MaxItems).value;
    for(var Index=0;Index<SaveItems.length;Index++)
    {
        SaveItems[Index].Title=document.getElementById("txtTitle_"+Index).value;
        SaveItems[Index].Checked=document.getElementById("checkBox_"+Index).checked;
        SaveItems[Index].IndexOrder=document.getElementById("txtIndexOrder_"+Index).value;
        SaveItems[Index].AdvImageId = document.getElementById("txtAdvImageId_"+Index).value;
    }
    
    
    retValue=Portal.CMS.AddAlbumItem.ServerSideAddAlbumItems(AlbumId,SaveItems).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    window.close();
}

function DeleteAlbumItem(AlbumId,AlbumIdItemId)
{
    ConfirmMsg=Portal.CMS.AlbumItems.GetConfirmMsg().value;
    if(confirm(ConfirmMsg)==false)return;
    retValue=Portal.CMS.AlbumItems.ServerSideDeleteAlbumItem(AlbumIdItemId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    alert(retValue);
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    document.getElementById("divContentData").innerHTML=Portal.CMS.AlbumItems.GetHtml(language,AlbumId).value;
}

function ClientSaveAlbumItem(AlbumId,AlbumItemId)
{
    AlbumItemName=document.getElementById("txtAlbumItemName").value;
    IndexOrder=document.getElementById("txtIndexOrder").value;
    retValue=Portal.CMS.UpdateAlbumItem.ServerSideAlbumItem(AlbumItemId,AlbumItemName,IndexOrder).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.close();
}

function ClientShowNewsItemForms(AlbumId)
{
    Url=Portal.CMS.Album.GetShowNewsItemForm(AlbumId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
}


function DetectAdvImageItem()
{
    selectedIndex=document.getElementById("divSelectAdvImage").selectedIndex;
    AdvImageId=document.getElementById("divSelectAdvImage").options[selectedIndex].value;
    value=Portal.CMS.AddAlbumItem.GetAdvImageText(AdvImageId).value;
    document.getElementById("divContentAdvImage").innerHTML=value;
}

function ClientSaveAlbumItems()
{
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    Max=document.getElementById("txtMaxItems").value;
    for(var Index=0;Index<Max;Index++)
    {
        Id=document.getElementById("txtId_"+Index).value;
        Subject=document.getElementById("txtSubject_"+Index).value;
        IndexOrder=document.getElementById("txtIndexOrder_"+Index).value;
        
        Portal.CMS.AlbumItems.ServerSideSaveAlbumItem(language,Id,Subject,IndexOrder).value;
    }   
    alert(Portal.CMS.AlbumItems.ServerSideGetSaveOkMsg().value);
}


function DetectHtmlBody(AlbumId)
{
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    retValue=Portal.CMS.AlbumItems.GetHtml(language,AlbumId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("divContentData").innerHTML=retValue;
}


function DetectUpdateAlbumBody(AlbumId)
{
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    retValue=Portal.CMS.UpdateAlbum.GetSubject(language,AlbumId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("txtAlbum").innerHTML=retValue;
}

function ClientPublishing(AlbumId)
{
    ConfirmMsg=Portal.CMS.Album.GetConfirmPublishingMsg().value;
    if(confirm(ConfirmMsg)==false)return;

    document.getElementById("divProcessing").innerHTML=Portal.CMS.Album.GetProcessingText().value;
    setTimeout("RealClientPublishing('"+AlbumId+"')",10);
}

function RealClientPublishing(AlbumId)
{
    retValue=Portal.CMS.Album.ServerSidePublishing(AlbumId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        document.getElementById("divProcessing").innerHTML="";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    alert(retValue);
}

function PublishingAlbumItem(AlbumItemId)
{
    ConfirmMsg=Portal.CMS.AlbumItems.GetConfirmPublishingMsg().value;
    if(confirm(ConfirmMsg)==false)return;

    document.getElementById("divProcessing").innerHTML=Portal.CMS.AlbumItems.GetProcessingText().value;
 
    setTimeout("RealPublishingAlbumItem('"+AlbumItemId+"')",10);
}

function RealPublishingAlbumItem(AlbumItemId)
{
    retValue=Portal.CMS.AlbumItems.ServerSideItemPublishing(AlbumItemId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        document.getElementById("divProcessing").innerHTML="";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    alert(retValue);
}




function FilterFunc()
{
    document.getElementById("divProcessing").innerHTML=Portal.CMS.Album.GetProcessingText().value;
    setTimeout("RealFilterFunc()",10);
}


function RealFilterFunc()
{
    belongSite=document.getElementById("drpSelectSiteForAlbum").options[document.getElementById("drpSelectSiteForAlbum").selectedIndex].value;
    retValue= Portal.CMS.Album.GetHtml(belongSite).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        document.getElementById("divProcessing").innerHTML="";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    document.getElementById("divAlbumMain").innerHTML=retValue;
}

function ReadingAlbumItem(AlbumId) {
    document.getElementById("divProcessing").innerHTML = Portal.CMS.AlbumItems.GetProcessingText().value;
    setTimeout("RealReadingAlbumItem('"+AlbumId+"')", 10);
}

function RealReadingAlbumItem(AlbumId) {
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    Html = Portal.CMS.AlbumItems.GetHtml(language, AlbumId).value;
    document.getElementById("divContentData").innerHTML = Html;
    document.getElementById("divProcessing").innerHTML = "";
}




function ClientSyncWithServer(AlbumId) {
    if (confirm(Portal.CMS.Album.GetConfirmSyncAllMsg().value) == false) {
        return;
    }
    document.getElementById("divProcessing").innerHTML = Portal.CMS.Album.GetProcessingText().value;
    setTimeout("RealClientSyncWithServer('" + AlbumId + "')", 10);
}

function RealClientSyncWithServer(AlbumId) {
    rValue = Portal.CMS.Album.ServerSideSyncWithServer(AlbumId).value;
    document.getElementById("divProcessing").innerHTML = "";
    alert(rValue);
}